﻿#include "BaseType.h"
#include "Tracer.h"
#include "Logger.h"
#include "Config.h"
using namespace libemb;

/*
LoggerManager:
{
    appLog =
    (
        {
            logPath="/data/log";
            logName="core";
            logNumberMax=10000;
            logStoreMax=1024;
            fileSizeMax=1; 
        },
        {
            logPath="/data/log";
            logName="call";
            logNumberMax=3000;
            logStoreMax=100;
            fileSizeMax=1;
        }
    );
};
*/

static void testLogger()
{
    Tracer::getInstance()->traceTimerBegin();
    for(int i=0;i<1000;i++) 
    {
        LOG_ON("core","[%08d] Logger pressure test......\n",i);
    }
    Tracer::getInstance()->traceTimerEnd();
    Tracer::getInstance()->traceTimerDuration();

    Tracer::getInstance()->traceTimerBegin();
    for(int i=0;i<1000;i++) 
    {
        LOG_ON("call","[%08d] Logger pressure test......\n",i);
    }
    Tracer::getInstance()->traceTimerEnd();
    Tracer::getInstance()->traceTimerDuration();
}

void TestLogger()
{
    Config config;
	config.initWithFile("logger.cfg");
	Settings logSettings = config["LoggerManager"]["appLog"];
	LoggerManager::getInstance()->initWithSettings(logSettings);
    while(1)
    {
        TRACE_DBG("------Logger test------\n");
        TRACE_DBG("1: test Logger\n");
        TRACE_DBG("q:quit.\n");
        std::string inputStr;
        std::cin >> inputStr;
        std::cout << inputStr << std::endl;
        if ("q" == inputStr || "quit" == inputStr) 
        {
            return;
        }
        else if ("1" == inputStr)
        {
            testLogger();
        }
        else
        {
            TRACE_DBG("Invalid command.\n");
        }
    }
}
